import axios from 'axios'
const _fetch = axios.create({
  baseURL: process.env.VUE_APP_URL
})
// 请求拦截器
_fetch.interceptors.request.use(
  function (config) {
    // 配置全局请求头authorization
    if (!config.headers.authorization) {
      config.headers.authorization = `Bearer ${window.localStorage.getItem(
        'token'
      )}`
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)
// 响应拦截器
_fetch.interceptors.response.use(
  function (response) {
    return response.data
  },
  function (error) {
    return Promise.reject(error)
  }
)
export default _fetch
